package com.luo.chengrui.module.sa.service.role;

import com.luo.chengrui.module.sa.service.role.RoleFolderModuleService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;

import java.util.*;
import com.luo.chengrui.module.sa.controller.admin.role.vo.*;
import com.luo.chengrui.module.sa.dal.dataobject.role.RoleFolderModuleDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;

import com.luo.chengrui.module.sa.convert.role.RoleFolderModuleConvert;
import com.luo.chengrui.module.sa.dal.mysql.role.RoleFolderModuleMapper;

import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.luo.chengrui.module.sa.enums.ErrorCodeConstants.*;;

/**
 * 角色分类模块配置表 Service 实现类
 *
 * @author 诚睿
 */
@Service
@Validated
public class RoleFolderModuleServiceImpl implements RoleFolderModuleService {

    @Resource
    private RoleFolderModuleMapper roleFolderModuleMapper;

    @Override
    public String createRoleFolderModule(RoleFolderModuleCreateReqVO createReqVO) {
        // 插入
        RoleFolderModuleDO roleFolderModule = RoleFolderModuleConvert.INSTANCE.convert(createReqVO);
        roleFolderModuleMapper.insert(roleFolderModule);
        // 返回
        return roleFolderModule.getId();
    }

    @Override
    public void updateRoleFolderModule(RoleFolderModuleUpdateReqVO updateReqVO) {
        // 校验存在
        validateRoleFolderModuleExists(updateReqVO.getId());
        // 更新
        RoleFolderModuleDO updateObj = RoleFolderModuleConvert.INSTANCE.convert(updateReqVO);
        roleFolderModuleMapper.updateById(updateObj);
    }

    @Override
    public void deleteRoleFolderModule(String id) {
        // 校验存在
        validateRoleFolderModuleExists(id);
        // 删除
        roleFolderModuleMapper.deleteById(id);
    }

    private void validateRoleFolderModuleExists(String id) {
        if (roleFolderModuleMapper.selectById(id) == null) {
            throw exception(ROLE_FOLDER_MODULE_NOT_EXISTS);
        }
    }

    @Override
    public RoleFolderModuleDO getByRoleFolderId(String roleFolderId) {
        return roleFolderModuleMapper.selectByRoleFolderId(roleFolderId);
    }

    @Override
    public List<RoleFolderModuleDO> getRoleFolderModuleList(Collection<String> ids) {
        return roleFolderModuleMapper.selectBatchIds(ids);
    }

    @Override
    public PageResult<RoleFolderModuleDO> getRoleFolderModulePage(RoleFolderModulePageReqVO pageReqVO) {
        return roleFolderModuleMapper.selectPage(pageReqVO);
    }

    @Override
    public List<RoleFolderModuleDO> getRoleFolderModuleList(RoleFolderModuleExportReqVO exportReqVO) {
        return roleFolderModuleMapper.selectList(exportReqVO);
    }

}
